package com.key.modules.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.key.modules.dto.CarrierPayDTO;
import com.key.modules.entity.CarrierSt;
import com.key.modules.mapper.CarrierPayMapper;
import com.key.modules.service.CarrierPayService;
import com.key.modules.vo.CarrierPayVO;
import com.key.modules.vo.CustomerReVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class CarrierPayServiceImpl implements CarrierPayService {

    @Autowired
    CarrierPayMapper carrierPayMapper;

    @Override
    public int creatCarrierStatement(CarrierSt carrierSt) {
        log.info("进入creatCarrierStatement方法，创建对账单"+
                "，statementNumber = "+carrierSt.getStatementNumber()+
                "，paymentObject = "+carrierSt.getPaymentObject()+
                "，billingTime = "+carrierSt.getBillingTime()+
                "，billingStatus = "+ carrierSt.getBillingStatus()+
                "，invoiceStatus = "+ carrierSt.getInvoiceStatus()+
                "，teaMoney = "+carrierSt.getTeaMoney()+
                "，abnormalState = "+carrierSt.getAbnormalState()+
                "，creationTime = "+carrierSt.getCreationTime()+
                "，creator = "+ carrierSt.getCreationTime()
        );
        //往数据库添加数据
        int resultInt=carrierPayMapper.insertCarrierSt(
                carrierSt.getStatementNumber(),carrierSt.getPaymentObject(),carrierSt.getBillingTime(),
                carrierSt.getBillingStatus(),  carrierSt.getInvoiceStatus(),carrierSt.getTeaMoney(),
                carrierSt.getAbnormalState(),carrierSt.getCreationTime(),carrierSt.getCreationTime()
        );

        log.info("creatCarrierStatement方法结束");
        return resultInt;
    }

    @Override
    public Map<String, Object> findCarrierPayable(CarrierPayDTO carrierPayDTO) {
        log.info("进入findCustomerReceivable方法，查找信息（支持高级搜索）"+
                "，CurrentPage = "+carrierPayDTO.getCurrentPage()+
                "，pageSize = "+carrierPayDTO.getPageSize()+
                "，承运商名称CName = "+carrierPayDTO.getCName()+
                "，创建时间Date = "+carrierPayDTO.getDate()+
                "，订单编号OrderNo = "+carrierPayDTO.getOrderNo()

        );
        //设置paage分页查询
        Page page=new Page<>(carrierPayDTO.getCurrentPage(),carrierPayDTO.getPageSize());
        Page<CarrierPayVO> reVOPage= carrierPayMapper.selectCarrierPay(page,carrierPayDTO.getCName(),carrierPayDTO.getDate(),
                carrierPayDTO.getOrderNo());
        //将获取的page里的total与数据返回
        List<CarrierPayVO> voList=reVOPage.getRecords();
        Map<String,Object> resultMap=new HashMap<>();
        resultMap.put("data",voList);
        resultMap.put("total",page.getTotal());

        log.info("findCarrierPayable方法结束返回数据");
        return resultMap;
    }

}
